package com.leon.picture.dao;

import java.util.List;

import com.leon.classify.domain.AdvertPic;
import com.leon.classify.domain.HeadAdvert;
import com.leon.classify.domain.HeadAdvertList;
import com.leon.classify.domain.User;
import com.leon.common.dao.CommonDao;

public class PictureDao extends CommonDao {
	
	//创建对象
	public void createObject(Object obj){
		this.getHibernateTemplate().saveOrUpdate(obj);
	}
	//得到图片
	public AdvertPic getAdvertPicById(String id){
		AdvertPic ap=(AdvertPic) super.getObject(AdvertPic.class, id);
		return ap;
	}
	//返回所有头部广告
	@SuppressWarnings("unchecked")
	public List<HeadAdvert> getAllHeadAdvert(){
		List<HeadAdvert> list=null;
		String hql="from HeadAdvert ha order by ha.displayOrder";
		list=this.qryObjectByHql(hql, null);
		return list;
	}
	//返回头部广告类
	public HeadAdvert getHeadAdvertById(String id){
		return (HeadAdvert) super.getObject(HeadAdvert.class, id);
	}
	//返回一个头部广告细项
	public HeadAdvertList getHeadAdvertListById(String id){
		return (HeadAdvertList) super.getObject(HeadAdvertList.class, id);
	}
	//删除一个对象
	public void delObject(Object obj){
		super.deleteObject(obj);
	}
	//得到头部中间的图片
	@SuppressWarnings("unchecked")
	public List<AdvertPic> getHeadAdvertPic(){
		String hql="from AdvertPic ap where ap.location=2 order by ap.displayOrder";
		List <AdvertPic>list=null;
		list=this.qryObjectByHql(hql, null);
		if(list!=null && list.size()>0){
			return list;
		}
		return null;
	}
	//得到所有二级页面的图片
	@SuppressWarnings("unchecked")
	public List<AdvertPic> getSecondPicList(){
		List<AdvertPic>list=null;
		String hql="from AdvertPic ap where ap.location=22 order by ap.displayOrder";
		list=this.qryObjectByHql(hql, null);
		if(list!=null&& list.size()>0){
			return list;
		}
		return null;
	}
	//获得所有用户
	@SuppressWarnings("unchecked")
	public List<User> getAllUser(){
		List<User>list=null;
		String hql="from User u ";
		list=this.qryObjectByHql(hql, null);
		if(list!=null && list.size()>0){
			return list;
		}
		return null;
	}
	//得到一个用户
	public User getUser(String id){
		return (User) super.getObject(User.class, id);
	}
	
	public User getUserByName(String userName,String password){
		String hql="from User u where u.userName='"+userName+"' and u.password='"+password+"'";
		List list=this.qryObjectByHql(hql, null);
		if (list !=null && list.size()>0){
			return (User) list.get(0);
		}else{
			return null;
		}
	}

}
